<?php

class User_RightactionmapController extends Zend_Controller_Action
{
	public function preDispatch(){
		
	}
	    
    public function saveAction(){
  		$delRow = $insertRow = $oldIdArr =  array();
    	$actions = $this->_request->getParam('actions',array());
    	$ur_id = $this->_request->getParam('ur_id','');

    	if(empty($ur_id)){
    		exit('save error.');
    	}

		$result = User_Service_Rightactionmap::getByUrid($ur_id);
		foreach ($result as $key => $val){
			$oldIdArr[] = $val['ura_id'];
		}
		$delIdArr = array_diff($oldIdArr,$actions);
		$insertIdArr = array_diff($actions,$oldIdArr);
		foreach ($delIdArr as $key => $val){
			$cond = array('ur_id'=>$ur_id,'ura_id'=>$val);
			$delRow[] = User_Service_Rightactionmap::deleteBy($ur_id,$val);
		}
		
		foreach ($insertIdArr as $key => $val){
			$cond = array('ur_id'=>$ur_id,'ura_id'=>$val);
			$insertRow[] = User_Service_Rightactionmap::add($cond);
		}
		
		if(count($delRow) || count($insertRow)){
			$data=array('ask'=>1);
			die(Zend_Json::encode($data));	
		}
    }
     
}